package com.zhuss.want.processor;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import com.zhuss.bean.bo.want.want.DeleteWantBo;
import com.zhuss.bean.vo.want.want.DetailWantVo;
import com.zhuss.want.db.dao.ext.WantDao;
import com.zhuss.want.db.entity.Want;
import com.zhuss.common.AbstractProcessor;
import com.zhuss.common.Processor;
import com.zhuss.db.entity.OpLog;
import com.zhuss.enums.LogActionEnum;
import com.zhuss.enums.MoudleEnum;
import com.zhuss.exception.WpsException;
import com.zhuss.util.JsonUtil;

/**
 * 删除求职 processor
 * @Author: zhushanshuo
 * @Date: 2019/9/24 19:54
 */
@Component("wantDelete")
public class WantDelete extends AbstractProcessor<Object, DeleteWantBo> implements Processor<Object, DeleteWantBo> {

    @Autowired
    private WantDao wantDao;
    
    @Autowired
	@Qualifier("wantRead")
	private WantRead wantRead;
    
    
    /**
     * 校验
     */
	@Override
    public void check(DeleteWantBo bo) throws WpsException {
    	
    }
    
    /**
     * 操作方法
     */
    @Override
    public Object process(DeleteWantBo param) throws WpsException {
    	Long wantId = param.getWantId();
    	String name = ((DetailWantVo) wantRead.detail(wantId)).getTitle();
    	
    	Want record = new Want();
    	record.setWantId(wantId);
    	record.setDeleted(param.getDeleted());
    	
    	record.setModifierId(param.getConcurrentUserId());
    	record.setModifier(param.getConcurrentUserName());
    	record.setModifyTime(new Date());
    	wantDao.delete(record);
    	param.setName(name);
        return null;
    }
    
    /**
     * 操作日志
     */
	@Override
	public Object log(DeleteWantBo param) throws WpsException {
		OpLog record = new OpLog();
    	record.setMoudle(MoudleEnum.求职.key());
    	record.setAction(LogActionEnum.求职删除.key());
    	record.setTargetId(param.getWantId());
    	record.setTargetName(param.getName());
    	record.setContent("参数: " + JsonUtil.toJson(param));
    	record.setReason(param.getExceptionReason());
    	
    	record.setCreatorId(param.getConcurrentUserId());
    	record.setCreator(param.getConcurrentUserName());
    	record.setCreateTime(new Date());
    	log(record);
    	return null;
	}
}
